<!--
 - IMG2BASE64 Convert Tools v0.1
 - Write by icyleaf.
 - Time: 05/08/2008
 - URI: http://www.icyleaf.cn
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>IMG2BASE64 Convert Tools</title>
<style type="text/css">
body{
    background: #BABABA url();
    font-size:0.9em;
    color: #595959;
    text-align: center;
}

a{color: #679C2F;}
a:hover{color: #994C4A}

hr{border:1px solid #A3A2A2}

#warp{
    margin: 0 auto;
    padding: 0;
    width: 620px;
    text-align: left;
}
#box{
    background: #E1E1E1;
    border: 1px solid #A3A2A2;
}

#box h1{
    background: #929292;
    font-size: 1.8em;
    color:#F5F5F5;
    margin: 0;
    padding: 0 0 0 5px;
}

div.list{padding: 10px 5px}

#imgurl, #base64encode{width:600px}


.red{color: red}
.bold{font-weight: bold}
</style>
</head>
<body>
<div id="warp">
    <div id="box">
        <h1>IMG2BASE64 Convert Tools</h1>
        <div class="list">
            <form action="<?php echo $_SERVICE['POST']; ?>" method="post">
                Image URI:(jpg|gif|png)<br />
                <input id="imgurl" type="text" name="imgurl" size="100" /><br />
                <input type="submit" name="submit" value="Get it!" />
            </form>

            <?php
            if(isset($_POST['imgurl']) && $_POST['imgurl']!=""){
                $file = $_POST['imgurl'];
                $suffix = substr($file, -3, 3);
                $tmp = substr($file, -4, 4);
                if($tmp!=".jpg" && $tmp!=".gif" && $tmp!=".png"){
                    echo "<span class=\"red bold\">Something is wrong, please check and try again.</span>";
                }else{
                    echo "<hr>Image URI: ".$file."<br />";
                    echo "Image type: <span class=\"red bold\">".$suffix."</span> | base64 encode:";

                    function get_content($url){
                        $ch = curl_init();

                        curl_setopt ($ch, CURLOPT_URL, $url);
                        curl_setopt ($ch, CURLOPT_HEADER, 0);

                        ob_start();

                        curl_exec ($ch);
                        curl_close ($ch);
                        $string = ob_get_contents();

                        ob_end_clean();

                        return $string;
                    }

                    $content = get_content ($file);
                    $result = base64_encode($content);
                    echo '<br /><textarea id="base64encode" rows="2" cols="100" onfocus="this.select()" onclick="this.select()">'.
                    $result.'</textarea></span>';

                    /* Just support open "allow_url_fopen" setting
                    $fp=fopen($file,"r");
                    $byte = "";
                    while (false !== ($char= fgetc($fp))) {
                        $byte .=$char;
                    }

                    $result = base64_encode($byte);
                    echo 'base64 encode: <br /><textarea id="base64encode" rows="5" cols="100">'.
                    $result.
                    "</textarea></span>";
                */
                }
                echo "<br />";
            }
            ?>
            <div style="float:right">Made by <a href="http://www.icyleaf.cn/">icyleaf</a></div>
            <a href="http://www.icyleaf.cn/2008/05/10/css-background-image-in-the-use-of-alternative/" target="_blank">How to use base64 encode of image into CSS files?</a>
        </div>
    </div>
</div>
</body>
</html>
